package com.atguigu.democustomer.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.democustomer.bean.Customer;
import com.atguigu.democustomer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.sound.midi.Soundbank;

@RestController
//@Controller
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @RequestMapping(value = "customerByname")
//    @ResponseBody
    public String getCustomerByName(@RequestParam("name") String na){
        String result = customerService.getCustomerByNameWithService(na);
        return result;
    }

    //一般适用场景是根据主键获取数据
    @RequestMapping("customerById/{id}")
    public String getCustomerById(@PathVariable("id") String id){
        String result = customerService.getCustomerByIdWithService(id);
        return result;
    }


    @PostMapping("saveCustomer")
    public void saveCustomer(@RequestBody Customer customer){
        System.out.println(customer);
//        customerService.saveOrUpdate(customer);
        customerService.saveCutomerWithService(customer);
    }


    @PostMapping("user-group-evaluate")
    public Long getCount(){
        return customerService.getCount();
    }

    @PostMapping("user-group-refresh/{id}")
    public String test(@PathVariable("id") String id,@RequestParam("busiDate") String busiDate){

        String jsonStr = "{\"id\":\"1\",\"name\":\"zs\",\"afe\":\"1000\"}";
        Customer customer = JSON.parseObject(jsonStr, Customer.class);
        return customer.toString();

    }
}
